@echo off
setlocal
call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars32.bat"
setlocal enabledelayedexpansion

del /q *.exe *.pdb *.i

set CFLAGS=/nologo /c /GS- /Gy- /GR- /Oi- /DWIN32_LEAN_AND_MEAN /std:c11
set LDFLAGS=/nologo /incremental:no /nodefaultlib /safeseh:no /merge:.rdata=.text /EMITPOGOPHASEINFO /entry:start /align:16 /OUT:webui.exe
set LIBS=kernel32.lib user32.lib Shlwapi.lib Advapi32.lib Ws2_32.lib httpapi.lib

if x%1 == xw (
    set CFLAGS=%CFLAGS% /O1
    set LDFLAGS=%LDFLAGS% /subsystem:windows /release
) else (
    if x%1 == xd (
        set CFLAGS=%CFLAGS% /Zi
        set LDFLAGS=%LDFLAGS% /subsystem:console /debug
    ) else (
        set CFLAGS=%CFLAGS% /O1
        set LDFLAGS=%LDFLAGS% /subsystem:console /release
    )
)

cl %CFLAGS% webui.c || goto err
link %LDFLAGS% webui.obj %LIBS% || goto err

del /q *.obj *.exp *.lib *.def

dir webui.exe

exit /b 0

:err
exit /b 1
